home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / tic / make_rev < prev    next >
Text File  |  1996-10-25  |  2KB  |  82 lines

  1. #!/bin/sh
  2. # @(#) make_rev 1.2 92/08/31 @(#)
  3. # make the reverse mapping file from a DNS database
  4. #
  5. # Copyright (c) 1992 by Texas Internet Consulting
  6. # This code may be freely copied and used so long as this
  7. # copyright notice is attached.  This code may not be sold
  8. # without the express written permission of Texas Internet Consulting.
  9. # Texas Internet Consulting makes no warranty as to the correctness
  10. # nor the applicability of this code for any purpose.
  11.  
  12. DNS_DOMAIN=$1
  13. DNS_NETWORK=$2
  14.  
  15. # the reverse  template file
  16. REV_HEAD=hosts.revhead
  17. # calculate the reverse domain from the network 
  18. # the assumption is subnets are divided along byte boundaries
  19. DNS_REVDOMAIN=`echo $DNS_NETWORK | awk -F. '{
  20.     for (i = NF; i>0; i--) {
  21.         if ($i == 0) continue
  22.         revdomain = revdomain $i "."
  23.     }
  24.     revdomain = substr(revdomain, 1, length(revdomain)-1)
  25.     print revdomain
  26. }'`
  27.  
  28. # update the serial field
  29. serial=`cat serial`
  30. echo "; $serial" >f.${DNS_NETWORK}
  31. sed "s/<SERIAL>/$serial/" ${REV_HEAD} >>f.${DNS_NETWORK}
  32. # build the reverse map
  33. awk '
  34. BEGIN {
  35.     domain = "'${DNS_DOMAIN}'."
  36.     reverse = "'${DNS_REVDOMAIN}'"
  37.     split(reverse, revbytes, ".")
  38.     nrevbytes = 0
  39.     for (i in revbytes)
  40.         nrevbytes++
  41. }
  42. /IN A|in a/ {
  43.     # hostname is a blank
  44.     if ($1 == "IN" && $2 == "A" || $1 == "in" && $2 == "a") {
  45.         address = $3
  46.     }
  47.     # special ugly nasty case - no reverse map for the domain itself
  48.     # an A record is added for non-mx mailers, but by convention the
  49.     # name of the domain gateway is domain.domain...
  50.     else if ($1 == "@") {
  51.         next
  52.     }
  53.     else {
  54.         host = $1
  55.         address = $4
  56.     }
  57.     # split the host address apart and reverse it
  58.     split(address, byte, ".")
  59.     for (i=1; i<=nrevbytes; i++) {
  60.         if (byte[i] != revbytes[nrevbytes-i+1])
  61.             break
  62.     }
  63.     # address is in this zone
  64.     if (i > nrevbytes) {
  65.         rev = ""
  66.         for (j=4; j>nrevbytes; j--) {
  67.             if (j < 4)
  68.                 rev = rev "."
  69.             rev = rev byte[j]
  70.         }
  71.         # print the PTR record
  72.         # if it end in a "." then do not create a PTR record
  73.         if (host !~ /\.$/) {
  74.             printf("%s IN PTR ",  rev)
  75.             if (host == "")
  76.                 printf("%s\n", domain)
  77.             else
  78.                 printf("%s.%s\n", host, domain)
  79.         }
  80.     }
  81. }' ${DNS_DOMAIN} >>f.${DNS_NETWORK}
  82.